/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#ifdef NodeGlobalData_DLL
#define NG_DLL __declspec(dllexport)
#else
#define NG_DLL __declspec(dllimport)
#endif



#include <面/面.h>
#include <物理/物理.h>
#include <MBT_Engine.h>
#include <JIT.h>

#include <unordered_map>
#include <stack>


typedef struct {
	int32	当前帧;
	ivec2	帧区间;
	float32	子帧;
	float32 帧率;
}S_时间帧;




struct NG_DLL S_节点数据 {
	static std::vector<std::vector<S_MapPtrItem>*> g_节点树容器;
	static std::vector<std::vector<S_MapPtrItem>*> g_纹理预览容器;

	static std::vector<S_MapPtrItem> g_包节点树;
	static std::vector<S_MapPtrItem> g_物体节点树;
	static std::vector<S_MapPtrItem> g_几何节点树;
	static std::vector<S_MapPtrItem> g_渲染节点树;
	static std::vector<S_MapPtrItem> g_函数节点树;
	static std::vector<S_MapPtrItem> g_材质节点树;
	static std::vector<S_MapPtrItem> g_着色节点树;
	static std::vector<S_MapPtrItem> g_物理节点树;

	static std::vector<S_MapPtrItem> g_渲染输出纹理;
	static std::vector<S_MapPtrItem> g_素材纹理;




	static std::vector<class C_节点树*>					g_根节点树;
	static std::vector<C_节点树*>						g_渲染根节点树;
	static std::map<std::u16string, E_值类型>			g_值类型名称映射;
	static std::map<std::u16string, C_节点树*>			G用于重新映射节点树到节点的容器;
	static std::map<std::u16string, class C_节点基类*>	G全局节点;


	static C_StrKey分配器		g_节点树名称分配器;
	static C_Key分配器			g_着色器ID分配器;
	static C_Key分配器			G_平行光ID;
	static C_Key分配器			G_点光源ID;
	static C_Key分配器			G_区域光ID;
	static C_Key分配器			G_聚光灯ID;

	static S_摄像机* g_当前操作视口相机;
	static S_Props				g_物理引擎视口互交;
	static vec3					g_视口鼠标点射线[2];
	static S_施加物理力			g_施加力;




	static std::string			g_工程文件节点代码路径;
	static std::string			g_工程文件几何节点代码绝对路径;
	static std::string			g_工程文件函数节点代码绝对路径;
	static std::string			g_工程文件材质节点代码绝对路径;
	static std::string			g_工程文件着色节点代码绝对路径;
	static std::string			g_编译器路径;


	static C_节点树* G当前包节点树;
	static C_节点树* G当前物体节点树;
	static C_节点树* G当前材质节点树;
	static C_节点树* G当前着色节点树;
	static C_节点树* G当前渲染节点树;
	static C_节点树* G当前并行节点树;
	static bool g_开启节点帧更新;
	static bool g_开启节点手动更新;
	static bool g_开启离线更新;


	static S_物体*				g_激活物体;
	//static std::set<S_物体*>	g_选中物体;
	static std::set<S_物体*>	g_编辑物体;
	static std::set<S_物体*>	g_辅助编辑物体;
	static std::set<S_物体*>	m_全局物体set;
	static std::set<S_物体*>	m_独立物体set;
	

	//static S_物体* m_包围盒物体;
	static S_Mesh* g_me_摄像机锥形;
	static S_Mesh* g_me_铰链轴;
	static S_Mesh* g_me_立方体;
	static S_Mesh* g_me_圆柱体;
	static S_Mesh* g_me_球体;
	static S_Mesh* g_me_平面;
	static S_Mesh* g_me_胶囊;
	static S_Mesh* g_me_链接线;
	static S_Mesh* g_me_灯光圆;
	static S_Mesh* g_me_灯光平行线;
	static S_Mesh* g_me_区域光四边线;
	static S_Mesh* g_me_四边型;
	static S_Mesh* g_me_十字叉;
	static S_Mesh* g_me_范围圆;
	static S_Mesh* g_me_胶囊封套端;
	static S_Mesh* g_me_胶囊封套管;
	static S_Mesh* g_me_边界框;
	static S_Mesh* g_me_虚拟体_X箭头;
	static S_Mesh* g_me_虚拟体_Y箭头;
	static S_Mesh* g_me_虚拟体_Z箭头;
	static S_Mesh* g_me_虚拟体_X旋转箭头;
	static S_Mesh* g_me_虚拟体_Y旋转箭头;
	static S_Mesh* g_me_虚拟体_Z旋转箭头;

	static S_Mesh* g_me_物理体_立方体;
	static S_Mesh* g_me_物理体_圆柱体;
	static S_Mesh* g_me_物理体_球体;
	static S_Mesh* g_me_物理体_平面;
	static S_Mesh* g_me_物理体_胶囊;


	//static C_StrKey分配器								g_物体名称分配器;
	//static std::unordered_map<std::u16string, S_Object*>	g_全局索引物体;
	

	static C_StrKey分配器						g_渲染世界名称分配器;
	static std::map<std::u16string, S_Object*>	g_渲染世界数据;
	
	static C_StrKey分配器						g_渲染层名称分配器;
	static std::map<std::u16string, S_Object*>	g_渲染层数据;
	
	static C_Key分配器		g_渲染层ID生成器;
	static S_Object*		g_渲染层大纲数据;


	static int32			g_物体全局渲染模式;
	static uint32			g_物体全局显示模式;
	static S_Prop枚举项* g_物体显示模式项_光追;
	static S_Prop枚举项* g_对称轴枚举项;
	static S_Prop枚举项* g_图像文件后缀;
	static S_Prop枚举项* g_视频文件后缀;
	static S_Prop枚举项* g_片源着色器类型项;
	static S_Prop枚举项* g_粒子包含属性;


	static int32		g_渲染帧编号;
	static S_GPU内存块	g_小字体纹理UV;
	static S_字体		g_字体_小;
	static S_纹理*		g_渲染器默认纹理;
	static S_纹理*		g_缺损环境颜色纹理;
	static S_纹理*		g_缺损环境深度纹理;
	//static S_纹理*		g_缺损阴影纹理;
	//static S_纹理*		g_缺损立方体阴影纹理;

	static S_GPU计算*	g毛笔笔刷_计算环境;
	static S_GPU计算*	g单色纹理笔刷_计算环境;

	static bool			g_开启节点更新;


	static std::set<S_Physics*>	g_物理引擎;
	static std::string			g流体缓存类型名称;
	static std::string			g流体缓存帧ID;







	//============================================== 材质 =================================================
	static S_材质管线* g_基本光照描边材质;
	static S_材质管线* g_基本光照轮廓材质;
	static S_材质管线* g_逐顶点线段描边材质;
	static S_材质管线* g_基本光照平面材质;


	static S_材质管线* g_权重可视线材质;
	static S_材质管线* g_权重可视面材质;
	static S_材质管线* g_索引绘制_颜色线段材质;
	static S_材质管线* g_索引绘制_颜色线材质;
	static S_材质管线* g_索引绘制_颜色点材质;

	static S_材质管线* g_索引绘制_图标材质;

	static S_材质管线* g_单色点材质;
	static S_材质管线* g_单色平直面材质;
	static S_材质管线* g_单色面材质;
	static S_材质管线* g_单色线框材质;
	static S_材质管线* g_单色描边材质;
	static S_材质管线* g_单色线段材质;
	static S_材质管线* g_单色连续线材质;

	static S_材质管线* g_单色连续虚线材质;
	static S_材质管线* g_单色线段虚线材质;

	static S_材质管线* g逐顶点线段材质;
	static S_材质管线* g逐顶点线段材质_朝向镜头;
	static S_材质管线* g逐顶点连续线材质;
	static S_材质管线* g逐顶点_点材质;

	static S_材质管线* g曲线材质;
	static S_材质管线* g曲线控制点材质;
	static S_材质管线* g曲线控制线材质;

	static S_材质管线* g数值标注材质;
	static S_材质管线* g数值标注线材质;
	static S_材质管线* g包围盒材质;
	static S_材质管线* g_AABB材质;

	static S_材质管线* gFLIP可视预览材质;
	static S_材质管线* g物理光照轮廓材质;
	static S_材质管线* g物理光照线材质;


	static S_纹理采样器* g_字体纹理采样器;




	static S_时间帧	g_场景帧;
	static std::stack<S_物体*>	g_删除物体;

	static S_板载缓存*		g_节点渲染摄像机矩阵;
	static S_纹理采样器*	g_场景渲染纹理采样器;



	//=========================== 节点 ==============================
	static std::map<std::u16string, std::vector<class C_扩展节点*>> g扩展节点库;


	//===================== 插件 ============================
	static C_StrKey分配器						g库名称分配器;
	static std::map<std::u16string, S_插件*>	g插件库;
	static std::map<std::u16string, void*>		g扩展节点参数;


	S_节点数据();
};





struct NG_DLL S_节点UI数据 {
	static S_Prop枚举项* g_对称轴枚举项;
	static S_Prop枚举项* g_物理可视项;
	static std::vector<S_标题和图标> g_物体显示模式标题和图标;
	static std::vector<S_标题和图标> g_视口显示模式标题和图标;
	static std::vector<S_标题和图标> g_视口显示模式标题和图标_光追;
};

struct NG_DLL S_虚拟体ID偏移 {
	static S_VkDrawIndexedIndirectCommand Indirect_交叉轴;
	static S_VkDrawIndexedIndirectCommand Indirect_方向轴;
	static S_VkDrawIndexedIndirectCommand Indirect_线框球;
};



struct NG_DLL S_射线拾取参数 {
	static vec3 g相机位置;
	static vec3 g开始射线;
	static vec3 g结束射线;
	static vec3 g手柄初始变换;
	static vec3 g垂足坐标;
	static vec3 g垂直线向量;
	static vec3 g交点S;
	static vec3 g交点E;
	static float32 g垂直线长度;
	static float32 g开始交点距离;
	static float32 g结束交点距离;
};



struct NG_DLL S_节点数据状态 {
	static S_Props g_是否打开了编辑模式;
	static S_Props g_网格编辑模式;
	static S_Props g_骨架编辑模式;
	static S_Props g_灯光编辑模式;
	static S_Props g_骨骼编辑模式;
	static S_Props g_骨骼姿态编辑模式;
	static S_Props g_3D视口显示模式;
};



struct NG_DLL S_NodeCtx_模拟计算 {
	static bool		g_是否更新节点;
	static bool		g_结束模拟解算;
	static S_Props	g_是否开启解算;
	static S_Props	g_节点解算;

};


struct NG_DLL S_节点框架 {
	static S_设备环境 ctx;
	static S_设备 GPU;

	static C_Widget管理*	g_UIGM;
	static S_设备环境*		g_3D视口环境;
	static S_设备环境*		g_UI视口环境;
	static S_设备环境*		g_UI合成环境;

	S_节点框架(){}
};


